import 'reflect-metadata'

// 定义一个装饰器工厂函数，可以返回方法和类的装饰器
export function UseInterceptors(...interceptors: Function[]) {
    return (target: object | Function, propertyKey?: string, descriptor?: PropertyDescriptor) => {
        // 如果有该值说明装饰的方法
        if (descriptor) {
            let oldInterceptors = Reflect.getMetadata('interceptors', descriptor.value) ?? [];
            Reflect.defineMetadata('interceptors', [...oldInterceptors, ...interceptors], descriptor.value);
        } else {
            let oldInterceptors = Reflect.getMetadata('interceptors', target) ?? [];
            Reflect.defineMetadata('interceptors', [...oldInterceptors, ...interceptors], target);
        }
    }
}
